// Addin.cpp : Implementation of CAddin

#include "stdafx.h"
#include "Addin.h"
#include "eLearningMis.h"
#include "WordCommand.h"

// CAddin

STDMETHODIMP CAddin::InterfaceSupportsErrorInfo(REFIID riid)
{
	static const IID* arr[] = 
	{
		&IID_IAddin
	};

	for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
	{
		if (InlineIsEqualGUID(*arr[i],riid))
			return S_OK;
	}
	return S_FALSE;
}

void CAddin::RegisterAsActive()
{
	//This helper function actually registers our
	//object as running in the running object table (ROT).
	//Register the object by passing the IUnknown pointer
	//to the object and the CLSID from our CWinApp object
	//which was given to us by AppWizard
	//HRESULT hr;
	//CeLearningMisApp *pApp = (CeLearningMisApp*)AfxGetApp();
	//hr=RegisterActiveObject(GetControllingUnknown(),
	//	pApp->GetAppCLSID(),
	//	ACTIVEOBJECT_WEAK,
	//	&m_dwCookie);
	//if(FAILED(hr))
	//{
	//	AfxMessageBox(_T("Didn't register Active Object"));
	//}
}

WordCommand wc;
STDMETHODIMP CAddin::SendCommand(BSTR bstrVal)
{
	AFX_MANAGE_STATE(AfxGetAppModuleState());

	if (wc.m_spApplication)
	{
		LPCSTR str = _com_util::ConvertBSTRToString( bstrVal );
		//wc.InstallCatAddin();
		//wc.Init_WordApplication();
		wc.CommandLines( str );
	}

	return S_OK;
}

//char* str = _com_util::ConvertBSTRToString( bstrVal );
//int i = 0;   int ret = 0;
//char* param[5];
//char* separator = "#";
//char* token = strtok( str , separator);
//while (token != NULL)
//{
//	param[i++] = token;
//	token = strtok( NULL , separator);						
//}

//CWordEdit we;
//we.InstallCatAddin();
//we.InitApplication();
//ret = we.WCommand(param[0] , param[1]);
//we.ExitWord();

//HRESULT hr;	LPCSTR str ;
	//if(m_spDoc) m_spDoc	= NULL;
	//hr = m_spApp->get_ActiveDocument( &m_spDoc );
	//if (SUCCEEDED(hr))
	//{
	//	m_WordCommand->m_ShortCut = this->m_ShortCut;
	//	m_WordCommand->m_hwnd = this->m_hWnd;
	//	m_WordCommand->m_FileVer = m_FileVer;
	//	hr = m_WordCommand->Init_WordApplication();
	//	if (SUCCEEDED(hr))
	//	{
	//		str = _com_util::ConvertBSTRToString( *command );
	//		m_WordCommand->CommandLines( str );
	//	}
	//	InstallATLEvent( TRUE );
	//	ATLTRACE("WEBBROWER START! \r\n");
	//}
	//return hr;